home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Shareware / Comunicatii / TrafMeter5 / TrafMeter56.exe / {app} / XSLExamples / month.xsl next >
Extensible Markup Language  |  2004-08-07  |  13KB  |  514 lines

  1. <?xml version="1.0"?>
  2. <xsl:template xmlns:xsl="uri:xsl">
  3.  
  4. <script>
  5. //
  6. // Version 1.3.
  7. // Copyright (c) 2003 Alexey Kazakovsky.
  8. //
  9. </script>
  10.  
  11. <style>
  12.  
  13. A { text-decoration: none; }
  14. A:HOVER { color: red; text-decoration: underline; }
  15.  
  16. h2.x { font-family: Arial,Verdana; font-size:14pt; };
  17. h3.x { font-family: Arial,Verdana; font-size:12pt; };
  18. p.x { font-family: Arial,Verdana; font-size:10pt; };
  19.  
  20. td.a0 { background-color:#F0F0F0; border-top:1px solid black; border-left:1px solid black; border-bottom:1px solid black; border-right:1px solid black; font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:13pt; margin-right:3pt; }
  21.  
  22. td.h0 { background-color:#F0F0F0; border-top:1px solid black; border-left:1px solid black; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:13pt; margin-right:3pt; }
  23. td.h1 { background-color:#F0F0F0; border-top:1px solid black; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; margin-left:3pt; margin-right:3pt; }
  24.  
  25. td.t {  font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:3pt; margin-right:3pt; }
  26. td.t0 { border-left:1px solid black; background:#FFFFFF; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:3pt; margin-right:3pt; }
  27. td.t1 { border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; margin-left:3pt; margin-right:3pt; }
  28.  
  29. </style>
  30.  
  31. <html>
  32. <body link="#0000FF" vlink="#0000FF">
  33. <script>
  34.  
  35.   var expDays = 30;
  36.   var expTime = new Date(); 
  37.   expTime.setTime(expTime.getTime() + (expDays * 24 * 60 * 60 * 1000));
  38.   var day_cookie = 'report_day';
  39.   var filter_cookie = 'report_filter';
  40.   var unit_cookie = 'report_unit';
  41.  
  42.   var Unit=0;
  43.   var Filter=0;
  44.   var FilterName='All';
  45.   var Year=0;
  46.   var Month=0;
  47.   var Day=0;
  48.   var DayIndex=0;
  49.  
  50.   // The array "Days" will be used to construct
  51.   // a list of available days from XML Traffic Report
  52.  
  53.   var Days=new Array(32); i=0;
  54.   while (i!=32)
  55.   {
  56.     Days[i]="0";
  57.     i++;
  58.   };
  59.  
  60.   // This function formats a traffic counter (cnt) for given traffic unit:
  61.   //   unit_no==0 - Bytes
  62.   //   unit_no==1 - KBytes
  63.   //   unit_no==2 - MBytes
  64.   //   unit_no==3 - GBytes
  65.  
  66.   function FormatCounter(cnt,unit_no)
  67.   {
  68.      var result=''; var t;
  69.      if (unit_no==0) { result=cnt; };
  70.      if (unit_no==1) { t=cnt/1024; t=t*10; t=Math.floor(t); t=t/10; result=t+' Kb'; };
  71.      if (unit_no==2) { t=cnt/1048576; t=t*100; t=Math.floor(t); t=t/100; result=t+' Mb'; };
  72.      if (unit_no==3) { t=cnt/1073741824; t=t*1000; t=Math.floor(t); t=t/1000; result=t+' Gb'; };
  73.      return result;
  74.   };
  75.  
  76.   function getMonthAsStr(month_no)
  77.   {
  78.      if (month_no==1) return 'January';
  79.      if (month_no==2) return 'February';
  80.      if (month_no==3) return 'March';
  81.      if (month_no==4) return 'April';
  82.      if (month_no==5) return 'May';
  83.      if (month_no==6) return 'June';
  84.      if (month_no==7) return 'July';
  85.      if (month_no==8) return 'August';
  86.      if (month_no==9) return 'September';
  87.      if (month_no==10) return 'October';
  88.      if (month_no==11) return 'November';
  89.      if (month_no==12) return 'December';
  90.      return 'null';
  91.   };
  92.  
  93.   // This function is like sprintf(result,"%02d",param_no);
  94.  
  95.   function format_02d(param_no)
  96.   {
  97.      var result=''; var q=Math.floor((param_no/10));
  98.      if (q==0) result='0'; result=result+param_no;
  99.      return result;
  100.   };
  101.  
  102.   function getDateFromYYMMDD(yymmdd)
  103.   {
  104.      var result='';
  105.      var myYear=2000+(Math.floor((yymmdd/10000)));
  106.      var myMonth=Math.floor((yymmdd%10000)/100);
  107.      var myDay=yymmdd%100;
  108.      result=getMonthAsStr(myMonth)+', '+format_02d(myDay)+' ';
  109.      return result;
  110.   };
  111.  
  112.   // name - name of the cookie
  113.   // * return string containing value
  114.   // of specified cookie or null if cookie
  115.   // does not exist
  116.   function getCookie(name) 
  117.   {
  118.     var prefix = name + "="
  119.     var cookieStartIndex = document.cookie.indexOf(prefix)
  120.     if (cookieStartIndex == -1)
  121.        return null
  122.     var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
  123.        prefix.length)
  124.     if (cookieEndIndex == -1)
  125.        cookieEndIndex = document.cookie.length
  126.     return unescape(document.cookie.substring(cookieStartIndex +
  127.        prefix.length,
  128.     cookieEndIndex))
  129.   }
  130.  
  131.   function setCookie(name, value)
  132.   {
  133.     var argv = setCookie.arguments;  
  134.     var argc = setCookie.arguments.length;
  135.     var expires=null; 
  136.     var path=null;
  137.     var domain=null;
  138.     var secure=false;
  139.  
  140.     argc=argc-2;
  141.     if (argc!=-1)
  142.     if (argc!=0)
  143.     {
  144.       expires=argv[2]; argc--;
  145.       if (argc!=0)
  146.       {
  147.         path=argv[3]; argc--;
  148.         if (argc!=0)
  149.         {
  150.            domian=argv[4]; argc--;
  151.            if (argc!=0) secure=argv[5];
  152.         };
  153.       };
  154.     };
  155.  
  156.     document.cookie = name + "=" + escape(value) + 
  157.     ((expires == null)? "": ("; expires=" + expires.toGMTString())) + 
  158.     ((path == null)? "": ("; path=" + path)) +  
  159.     ((domain == null)? "": ("; domain=" + domain)) +    
  160.     ((secure == true)? "; secure": "");
  161.   }      
  162.  
  163.   function deleteCookie(name)
  164.   {
  165.     var expTime = new Date();  
  166.     expTime.setTime(expTime.getTime() - 1);   
  167.     var cval = getCookie(name);  
  168.     document.cookie = name + "=" + cval + "; expires=" + expTime.toGMTString();
  169.   } 
  170.  
  171.   function change_day(Index)
  172.   {
  173.     Day=select_day.options[Index].value;
  174.     setCookie(day_cookie,Day);
  175.     setCookie(filter_cookie,0);
  176.     setCookie(unit_cookie,Unit);
  177.     document.location.reload();
  178.   };
  179.  
  180.   function change_filter(Index)
  181.   {
  182.     Filter=Index;
  183.     setCookie(filter_cookie,Filter);
  184.     setCookie(day_cookie,0);
  185.     setCookie(unit_cookie,Unit);
  186.     document.location.reload();    
  187.   };
  188.  
  189.   function change_fullreport()
  190.   {
  191.     setCookie(unit_cookie,Unit);
  192.     setCookie(filter_cookie,0);
  193.     setCookie(day_cookie,0);
  194.     document.location.reload();    
  195.   };
  196.  
  197.   function change_unit(Index)
  198.   {
  199.      setCookie(unit_cookie,Index);
  200.      setCookie(filter_cookie,Filter);
  201.      setCookie(day_cookie,Day);
  202.      document.location.reload();    
  203.   };
  204.  
  205.   function out_tblheader(colname1,colname2,colname3,colname4)
  206.   {
  207.     document.write('<tr>');
  208.     document.write('<td class="h0"><B>');
  209.     document.write(colname1);
  210.     document.write('</B></td>');
  211.     document.write('<td class="h0"><B>');
  212.     document.write(colname2);
  213.     document.write('</B></td>');
  214.     document.write('<td class="h0"><B>');
  215.     document.write(colname3);
  216.     document.write('</B></td>');
  217.     document.write('<td class="h1"><B>');
  218.     document.write(colname4);
  219.     document.write('</B></td>');
  220.     document.write('</tr>');
  221.   };
  222.  
  223.   Day=getCookie(day_cookie);
  224.   if (Day==-1) Day=0;
  225.   if (Day==null) Day=0;
  226.   deleteCookie(day_cookie);
  227.  
  228.   Filter=getCookie(filter_cookie);
  229.   if (Filter==null) Filter=0;
  230.   deleteCookie(filter_cookie);
  231.  
  232.   Unit=getCookie(unit_cookie);
  233.   if (Unit==null) Unit=0;
  234.   deleteCookie(unit_cookie);
  235.  
  236. </script>
  237.  
  238. <xsl:for-each select="TrafficReport/Filter/Day">
  239. <script>
  240.  
  241.   // This will make a list of avalaible days
  242.   // from monthly XML Traffic Reports.
  243.  
  244.   var dt = parseInt("<xsl:value-of select="@dt"/>",10);
  245.   Year=Math.floor((dt/10000))+2000;
  246.   Month=Math.floor((dt%10000)/100);
  247.   dt=dt%100;
  248.   Days[dt]="1";
  249. </script>
  250. </xsl:for-each>
  251.  
  252. <xsl:for-each select="TrafficReport/Filter">
  253. <script>
  254.   var f = parseInt("<xsl:value-of select="@Id"/>",10);
  255.   if (f==Filter) FilterName=new String('<xsl:value-of select="Name"/>');
  256. </script>
  257. </xsl:for-each>
  258.  
  259. <Script>
  260. //
  261. //   Begin of output a top menu
  262. //
  263. </Script>
  264.  
  265. <table border="0" cellspacing="0" cellpadding="3">
  266. <tr>
  267. <td>
  268.  
  269. <table border="0" cellspacing="0" cellpadding="6">
  270. <tr><td class="a0">
  271.  
  272. <a href="javascript:change_fullreport()">Full monthly report</a>
  273.  
  274. </td></tr>
  275. </table>
  276.  
  277. </td>
  278. <td>
  279.  
  280. <table border="0" cellspacing="0" cellpadding="3"><tr><td class="a0">
  281. Report for the specific day
  282. <select name="select_day" onchange="change_day(selectedIndex)" >
  283. <option value="0">All days</option>
  284. <script>
  285. i=1; j=1;
  286. while (i!=32)
  287. {
  288.   if (Days[i]!="0")
  289.   {
  290.      if (Day==i) DayIndex=j;
  291.      document.write('<option value="');
  292.      document.write(i);
  293.      document.write('">');
  294.      document.write(i);
  295.      document.write('</option>');
  296.      j++;
  297.   };
  298.   i++;
  299. };
  300. select_day.selectedIndex=DayIndex;
  301. </script>
  302. </select>
  303. </td></tr></table>
  304.  
  305. </td>
  306. <td>
  307.  
  308. <table border="0" cellspacing="0" cellpadding="3">
  309. <tr><td class="a0">
  310.  
  311. Show counters in
  312.  
  313. <select name="select_unit" onchange="change_unit(selectedIndex)" >
  314. <option value="0">Bytes</option>
  315. <option value="1">KBytes</option>
  316. <option value="2">MBytes</option>
  317. <option value="3">GBytes</option>
  318. </select>
  319. <script>
  320. select_unit.selectedIndex=Unit;
  321. </script>
  322.  
  323. </td></tr></table>
  324.  
  325. </td></tr></table>
  326.  
  327. <Script>
  328. //
  329. //   End of output the top menu
  330. //
  331. </Script>
  332.  
  333. <H2 class="x">Your company name</H2>
  334. <H3 class="x">Traffic report for: 
  335. <script>
  336. document.write(getMonthAsStr(Month));
  337. if (Day!=0)
  338. {
  339.   document.write(', ');
  340.   document.write(format_02d(Day));
  341. };
  342. document.write(' ');
  343. document.write(Year);
  344. </script>
  345. </H3>
  346.  
  347. <H3 class="x">
  348. <script>
  349. if (Filter==0)
  350. {
  351.    document.write('Filters: All');
  352. }
  353. else
  354. {
  355.    var str='Filter: '+FilterName+', FilterId='+Filter;
  356.    document.write(str);
  357. };
  358. </script>
  359. </H3>
  360.  
  361. <script>
  362. // 
  363. //    Begin of output a table with counters
  364. //   
  365. var header=0;
  366. </script>
  367.  
  368. <table cellpadding="4" border="0" cellspacing="0">
  369. <xsl:for-each select="TrafficReport/Filter">
  370. <script>
  371.  
  372.   if (Filter==0)
  373.   if (Day==0)
  374.   {
  375.     if (header==0)
  376.     {
  377.       out_tblheader('FilterId','Filter Name','Sent bytes','Recv bytes');
  378.       header=1;
  379.     };
  380.  
  381.     document.write('<tr>');
  382.  
  383.     document.write('<td class="t0">');
  384.     var f = parseInt("<xsl:value-of select="@Id"/>",10);
  385.  
  386.     var s='<a href="javascript:change_filter('+f+')">'+f+'</a>';
  387.     document.write(s);
  388.     document.write('</td>');
  389.  
  390.     document.write('<td class="t0">');
  391.     document.write('<xsl:value-of select="Name"/>');
  392.     document.write('</td>');
  393.  
  394.     var sent=parseInt("<xsl:value-of select="Sent"/>",10);
  395.     var recv=parseInt("<xsl:value-of select="Recv"/>",10);
  396.  
  397.     document.write('<td class="t0">');
  398.     document.write(FormatCounter(sent,Unit));
  399.     document.write('</td>');
  400.  
  401.     document.write('<td class="t1">');
  402.     document.write(FormatCounter(recv,Unit));
  403.     document.write('</td>');
  404.  
  405.     document.write('</tr>');
  406.  
  407.   };
  408.  
  409.   if (Filter==0)
  410.   if (Day!=0)
  411.   {
  412.     var dt='0'+(Year-2000)+format_02d(Month)+format_02d(Day);
  413.  
  414.     if (header==0)
  415.     {
  416.       out_tblheader('FilterId','Filter Name','Sent bytes','Recv bytes');
  417.       header=1;
  418.     };
  419.  
  420.     document.write('<tr>');
  421.  
  422.     document.write('<td class="t0">');
  423.     var f = parseInt("<xsl:value-of select="@Id"/>",10);
  424.     var s='<a href="javascript:change_filter('+f+')">'+f+'</a>';
  425.     document.write(s);
  426.     document.write('</td>');
  427.  
  428.     document.write('<td class="t0">');
  429.     document.write('<xsl:value-of select="Name"/>');
  430.     document.write('</td>');
  431.  
  432.     var sent=0;
  433.     var recv=0;
  434.  
  435.     <xsl:for-each select="Day">
  436.       var day_dt=parseInt("<xsl:value-of select="@dt"/>",10);
  437.       if (day_dt==dt)
  438.       {
  439.          sent=parseInt("<xsl:value-of select="Sent"/>",10);
  440.          recv=parseInt("<xsl:value-of select="Recv"/>",10);
  441.       };
  442.     </xsl:for-each>
  443.  
  444.     document.write('<td class="t0">');
  445.     document.write(FormatCounter(sent,Unit));
  446.     document.write('</td>');
  447.  
  448.     document.write('<td class="t1">');
  449.     document.write(FormatCounter(recv,Unit));
  450.     document.write('</td>');
  451.  
  452.     document.write('</tr>');
  453.  
  454.   };
  455.  
  456.   if (Filter!=0)
  457.   if (Day==0)
  458.   {
  459.     if (header==0)
  460.     {
  461.       out_tblheader('FilterId','Day','Sent bytes','Recv bytes');
  462.       header=1;
  463.     };
  464.  
  465.     var f = parseInt("<xsl:value-of select="@Id"/>",10);
  466.     if (f == Filter)
  467.     {
  468.        <xsl:for-each select="Day">
  469.  
  470.          document.write('<tr>');
  471.  
  472.          document.write('<td class="t0">');
  473.          document.write(f);
  474.          document.write('</td>');
  475.  
  476.      var dayAttr=parseInt("<xsl:value-of select="@dt"/>",10);
  477.  
  478.          document.write('<td class="t0">');
  479.          document.write(getDateFromYYMMDD(dayAttr));
  480.          document.write('</td>');
  481.  
  482.          var sent=0;
  483.          var recv=0;
  484.  
  485.          sent=parseInt("<xsl:value-of select="Sent"/>",10);
  486.          recv=parseInt("<xsl:value-of select="Recv"/>",10);
  487.  
  488.          document.write('<td class="t0">');
  489.          document.write(FormatCounter(sent,Unit));
  490.          document.write('</td>');
  491.  
  492.          document.write('<td class="t1">');
  493.          document.write(FormatCounter(recv,Unit));
  494.          document.write('</td>');
  495.  
  496.          document.write('</tr>');
  497.  
  498.       </xsl:for-each>
  499.     };
  500.   };
  501.  
  502. </script>
  503. </xsl:for-each>
  504. </table>
  505.  
  506. <p><br>
  507. <i>Last Modified:
  508. <xsl:value-of select="TrafficReport/LastModified"/>
  509. </i></br>
  510. </p>
  511.  
  512. </body></html>
  513. </xsl:template>
  514.